package com.tuanzi.loan.business.service.receipt.statistics.impl;

import com.google.common.collect.Lists;
import com.tuanzi.loan.business.entity.receipt.statistics.ReceiptBalanceOperationRecord;
import com.tuanzi.loan.business.entity.system.Dictionary;
import com.tuanzi.loan.business.repository.receipt.statistics.ReceiptBalanceOperationRecordRepository;
import com.tuanzi.loan.business.service.receipt.statistics.ReceiptBalanceOperationRecordService;
import com.tuanzi.loan.business.service.system.DictionaryService;
import com.tuanzi.loan.core.aspect.Debug;
import com.tuanzi.loan.core.service.CommonServiceImpl;
import com.tuanzi.loan.vo.view.receipt.statistics.ReceiptBalanceOperationRecordView;
import org.apache.commons.collections4.ListUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

/**
 * @author lsx
 */
@Debug
@Service
@Transactional
public class ReceiptBalanceOperationRecordServiceImpl extends CommonServiceImpl<ReceiptBalanceOperationRecord, Integer> implements ReceiptBalanceOperationRecordService {

    @Autowired
    private ReceiptBalanceOperationRecordRepository balanceOperationRecordRepository;
    @Autowired
    private DictionaryService dictionaryService;

    @Override
    protected JpaRepository<ReceiptBalanceOperationRecord, Integer> getRepository() {
        return balanceOperationRecordRepository;
    }

    @Override
    public ReceiptBalanceOperationRecordView findRecordResponseByUserId(String userId, Date startTime, Date endTime) {
        return balanceOperationRecordRepository.findOperationRecordViewByUserId(userId, startTime, endTime);
    }

    @Override
    public List<ReceiptBalanceOperationRecordView> findRecordResponseSourceFromByUserId(String userId, Date startTime, Date endTime) {
       return balanceOperationRecordRepository.findRecordResponseSourceFromByUserId(userId, startTime, endTime);
    }


    @Override
    public Long findSettleAmountByProductIdAndSourceFrom(Long productId, Integer sourceFrom, Date startTime, Date endTime) {
        return balanceOperationRecordRepository.findSettleAmountByProductIdAndSourceFrom(productId, sourceFrom, startTime, endTime);
    }
}
